//操作员列表 0

//(function(){
define(function(require,exports,module){
	"require:nomunge,exports:nomunge,module:nomunge";
	
   //	异步请求
	var wind_async=require('ddf_wind_async');
		
	var base=require('component-base');
		
	var history=require('component-history');
	
	require('component-page');
    var pageIndex=0;

var tips_index=0;

var staffId,realName;

/**
 * 查询操作员列表
 */
//function loadOperatorList() {
exports.init=function(m){
	history.addHis(this,arguments);//增加历史
	window.$ddf_operator = m;
	staffId="";
	realName="";
	
	pageIndex=0;
	var htmlStr="";

	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">操作员查询</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';

	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">店员编码：</label><div class="controls"><input class="span8 m-wrap" type="text" id="staffId"/></div></div></div>';
	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">真实姓名：</label><div class="controls"><input class="span8 m-wrap" type="text" id="realName"/></div></div></div>';
	htmlStr += '</div>   ';

	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_operator.searchOperator()">搜索</button>';
	htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_operator.resetSearchParams()">重置</button>';
	htmlStr += '</div>        ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>店员列表</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr>';
	htmlStr += '<th>序号</th>';
	htmlStr += '<th>店员编码</th>';
	htmlStr += '<th>登录用户名</th>';
	htmlStr += '<th>真实姓名</th>';
	htmlStr += '<th>职位</th>';
	htmlStr += '</tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody id="operatorList">';
	htmlStr += '</tbody>';
	htmlStr += '</table>';
	htmlStr += '<div id="footPageDiv'+pageIndex+'">';

	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';

//	$("#content0").css("display", "block");
	
	showDiv("content0");

	$("#content0").html(htmlStr);


	getQueryOperatorList(1,pageSize,staffId,realName);



}

/**
 * 查询操作员列表
 */
function getQueryOperatorList(pageNumber,pageSize,staffId,realName){
	
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize" :pageSize,
			"staffId":staffId,
			"realName":realName
	        };
	
	tips_index=0;

	base.showLoading();
	
//	DDF_AsyncRequest("POST",ddf.operator.queryOperator,params,'$ddf_operator.getQueryOperatorListCallBack(data)');
	 eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.operator.queryOperator,params));
			
			getQueryOperatorListCallBack(data);
			
		}))().start();
}

/**
 * 查询会员列表_回调函数
 */
function getQueryOperatorListCallBack(data){
	
	if(data["code"]==1){
		var htmlStr = "";

		for (var i = 0; i < data["operatorListData"].length; i++) {

			htmlStr += '<tr>';
			htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
			htmlStr += '<td>'+data["operatorListData"][i]["STAFF_ID"]+'</td>';
			htmlStr += '<td>'+data["operatorListData"][i]["USER_NAME"]+'</td>';
			htmlStr += '<td>'+data["operatorListData"][i]["REAL_NAME"]+'</td>';
			htmlStr += '<td>'+data["operatorListData"][i]["POSITION_ID"]+'</td>';
			
			htmlStr += '</tr>';

		}


		$("#operatorList").html(htmlStr);

//		setPage(pageIndex,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_operator");

		 $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 changePageCallback:function(pageSize,page){  
				 getQueryOperatorList(page,pageSize,staffId,realName);
			 },
			 changePageSizeCallBack:function(pageSize){
				 getQueryOperatorList(1,pageSize,staffId,realName);
			 } 
	     }); 
	}else{
		
		 base.tips_error(data["message"]);
	}


	
	base.cancelLoading();
	
}


/**
 * 重置参数
 */
function resetSearchParams(){
	
	staffId="";
	realName="";
	$("#staffId").val("");
	$("#realName").val("");
	
	
	
}

/**
 * 搜索终端
 */
function searchOperator(){
	
	tips_index=0;
	
	staffId=$("#staffId").val();
	realName=$("#realName").val();
	
	getQueryOperatorList(1,pageSize,staffId,realName);
	
}



function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
}

//暴露方法
exports.getQueryOperatorList=getQueryOperatorList;
exports.getQueryOperatorListCallBack = getQueryOperatorListCallBack;
exports.resetSearchParams=resetSearchParams;
exports.searchOperator=searchOperator;

});
//})();